package com.xlh.support.training.controller;

import com.xlh.common.Result;
import com.xlh.support.training.po.TrainingManualSavePO;
import com.xlh.support.training.service.TrainingManualService;
import com.xlh.support.training.vo.TrainingManualVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author cheer
 */
@Api("实训手册管理")
@RestController
@RequestMapping("/training/manual")
public class TrainingManualController {

    @Autowired
    private TrainingManualService trainingManualService;

    @ApiOperation("查询环境实训实验手册")
    @GetMapping("/{trainingId}")
    public Result<TrainingManualVO> queryTrainingManual(@PathVariable("trainingId") Long trainingId) {
        TrainingManualVO trainingManualVO = trainingManualService.getTrainingManual(trainingId);
        return Result.success(trainingManualVO);
    }

    @ApiOperation("查询环境实训实验手册Markdown")
    @GetMapping("/md/{trainingId}")
    @PreAuthorize("@permissionValidator.isAdminOrTeacher()")
    public Result<String> queryTrainingManualMd(@PathVariable("trainingId") Long trainingId) {
        String trainingManual = trainingManualService.getTrainingManualMd(trainingId);
        return Result.success(trainingManual);
    }

    @ApiOperation("保存环境实训实验手册")
    @PostMapping("/{trainingId}")
    @PreAuthorize("@permissionValidator.isAdminOrTeacher()")
    public Result saveTrainingManual(@PathVariable("trainingId") Long trainingId,
                                     @RequestBody TrainingManualSavePO trainingManualSavePO) {
        trainingManualService.saveTrainingManual(trainingId, trainingManualSavePO);
        return Result.success();
    }
}
